package com.example.buyticketlishi.view.ac;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.baselibrary.Base.BaseActivity;
import com.example.baselibrary.Utils.SelfToastUtil;
import com.example.baselibrary.Utils.ToastUtil;
import com.example.buyticketlishi.R;
import com.example.buyticketlishi.RetrufitHelp.BaseSubscriber;
import com.example.buyticketlishi.RetrufitHelp.ExceptionHandle;
import com.example.buyticketlishi.RetrufitHelp.RetrofitClient;
import com.example.buyticketlishi.bean.LSVemPayOrderRequestBean;
import com.example.buyticketlishi.bean.LSVemPayOrderResultBean;
import com.example.buyticketlishi.utils.PeterTimeCountRefresh;

public class PaySelectActivity extends BaseActivity {

    private Button btBack;
    private Button btHome;

    private String orderBatchNo;
    private String allMoney;
    private String paymentTypeId;
    private String printTicketMode = "2";


    private ImageView zfbSelect;
    private ImageView wxSelect;
    private String qrCode;
    private boolean isClickZFB;
    private boolean isClickWX;

    private EditText etScan;
    private String barcode = "";
    private static final int PROCESSOR_QRCODE = 10;
    private String string;


    private LSVemPayOrderRequestBean payOrderRequestBean;
    private TextView tvMoney;
    private PeterTimeCountRefresh timer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    protected int getView() {

        return R.layout.activity_pay_select;
    }

    @Override
    public void init() {
        Intent intent = getIntent();
        orderBatchNo = intent.getStringExtra("orderBatchNo");
        allMoney = intent.getStringExtra("allMoney");

        btBack = findViewById(R.id.bt_select_back);
        btHome = findViewById(R.id.bt_back_home);
        zfbSelect = findViewById(R.id.zfb_select_show);
        wxSelect = findViewById(R.id.wx_select_show);
        etScan = findViewById(R.id.et_scan);
        tvMoney = findViewById(R.id.tv_select_money);


        tvMoney.setText("待付款金额:" + allMoney);
        doThing();

        timer = new PeterTimeCountRefresh(1000 * 300, 1000, (TextView) findViewById(R.id.tv_over_time));
        timer.start();
        timer.setTimeOverListener(new PeterTimeCountRefresh.TimeOverListener() {
            @Override
            public void timeOver() {
                //倒计时结束，结束页面
                startActivity(new Intent(PaySelectActivity.this,MainActivity.class));
            }
        });
    }

    private void doThing() {

        zfbSelect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //请将二维码对准，下方扫描框
                paymentTypeId = "2469L";
//                etScan.requestFocus();
//                qrCode = "";
//                payOrderRequestBean.setPaymentTypeId(paymentTypeId);
//                SelfToastUtil.getInstance().show("请将二维码对准下方扫描框");
//                isClickZFB = true;
//                isClickWX = false;

                //选择了方式，跳转下一个界面
                Intent intent = new Intent(PaySelectActivity.this, PayMoneyActivity.class);
                intent.putExtra("orderBatchNo", orderBatchNo);
                intent.putExtra("paymentTypeId", paymentTypeId);
                intent.putExtra("allMoney", allMoney);
                startActivity(intent);
            }
        });

        wxSelect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                paymentTypeId = "2468L";
//                etScan.requestFocus();
//                qrCode = "";
//                payOrderRequestBean.setPaymentTypeId(paymentTypeId);
//                SelfToastUtil.getInstance().show("请将二维码对准下方扫描框");
//                isClickZFB = false;
//                isClickWX = true;

                //选择了方式，跳转下一个界面
                Intent intent = new Intent(PaySelectActivity.this, PayMoneyActivity.class);
                intent.putExtra("orderBatchNo", orderBatchNo);
                intent.putExtra("paymentTypeId", paymentTypeId);
                intent.putExtra("allMoney", allMoney);
                startActivity(intent);
            }
        });

        btBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        btHome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(PaySelectActivity.this,MainActivity.class));
            }
        });
    }


    @Override
    protected void onStart() {
        super.onStart();
        etScan.requestFocus();
    }

    @Override
    protected void onResume() {
        super.onResume();
        etScan.requestFocus();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (timer != null) {
            timer.cancel();
        }
    }
}
